package com.yuanyefu.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 * Created by Administrator on 2017/9/17 0017.
 */
@Aspect
public class SecurityAspect {
    @Around("execution(* com.yuanyefu.aop.UserService.login(..))")
    public Object securityCheck(ProceedingJoinPoint pjp) throws Throwable {
        String username = (String) pjp.getArgs()[0];
        System.out.println("[security check] username = "+username);
        if (!"admin".equals(username))
            return pjp.proceed();
        System.out.println("[security check] admin is forbidden!");
        return new RuntimeException("Forbidden");
    }
}
